package com.ddstation.onsitelaw.utils;



import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringHandleUtil {



    // 判断一个字符串是否都为数字
    public static boolean  isDigit(String strNum) {
        Pattern pattern = Pattern.compile("[0-9]{1,}");
        Matcher matcher = pattern.matcher((CharSequence) strNum);
        return matcher.matches();
    }

    //截取数字
    public static Integer getNumbers(String content) {
        Pattern pattern = Pattern.compile("\\d+");
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()) {
            return Integer.parseInt(matcher.group(0));
        }
        return 0;
    }

    // 截取非数字
    public static String splitNotNumber(String content) {
        Pattern pattern = Pattern.compile("\\D+");
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()) {
            return matcher.group(0);
        }
        return "";
    }

    /**
     * 取连续数字
     *
     * @param str
     * @return
     */
    private static Set<Integer> getNumsFromStr(String str) {

        String[] ary = str.replaceAll("[^\\d]", " ").split("\\s+");

        Set<Integer> set = new TreeSet<Integer>();

        for (String num : ary) {
            if (!num.trim().equals("")) {
                set.add(new Integer(num.trim()));
            }
        }

        return set;
    }

    /**
     * 是否包含数字
     *
     * @param str
     * @return
     */
    public static boolean isNum(String str) {
        return str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");
    }
}
